package com._54programer.sourcecode.event;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractEventMulticaster implements  EventMulticaster{

    private List<WeatherListener> listeners = new ArrayList<>();

    @Override
    public void multicastEvent(WeatherEvent event) {
        doStart();
        listeners.forEach(i->i.onWeatherEvent(event));
        doEnd();
    }

    @Override
    public void addListener(WeatherListener weatherListener) {
        listeners.add(weatherListener);
    }

    @Override
    public void removeListener(WeatherListener weatherListener) {
        listeners.remove(weatherListener);
    }

    protected abstract void doStart();
    protected abstract void doEnd();

}
